package com.cdj.common.behavior;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;

/**
 * ---------------------------------------------------------<br />
 * desc：<br />
 * author：chendeji <br />
 * date：2021/7/8<br />
 * email：18701434169@163.com<br />
 * qq: 781571323
 * wx: melody_2009
 * ---------------------------------------------------------<br />
 */
public class MultiLoadingDataBehavior extends BaseLoadingBehavior<Void, Void>{
    List<BaseLoadingBehavior> behaviors = new ArrayList<>();

    public void addBehavior(BaseLoadingBehavior behavior) {
        this.behaviors.add(behavior);
    }

    @Override
    public void request() {
        for (int i = 0; i < behaviors.size(); i++) {
            behaviors.get(i).request();
        }
    }

    public void syncRequest() {
        for (int i = 0; i < behaviors.size(); i++) {
            int finalI = i;
            Runnable runnable = () -> behaviors.get(finalI).request();
            Executors.newSingleThreadExecutor().submit(runnable);
        }
    }
}
